#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<assert.h>
#include<string.h>

size_t my_strlen(const char* str)
{
	size_t count = 0;
	while (*str)
	{
		count++;
		str++;
    }
	return count;
}

size_t my_strlen1(const char* str)
{
	assert(str);
	if (*str == '\0')
		return 0;
	else
		return 1 + my_strlen(str + 1);
}

size_t my_strlen2(const char* str)
{
	assert(str);
	char* p = str;
	while (*str)
	{
		str++;
	}
	return str - p;
}


char* my_strcpy(char* dest, const char* src)
{
	char* ret = dest;
	assert(dest != NULL);
	assert(src != NULL);
	while (*dest++=*src++)
	{
		;
	}
	return ret;
}


char* my_strcat(char* dest, const char* src)
{
	char* ret = dest;
	assert(dest != NULL);
	assert(src != NULL);
	while (*dest)
	{
		dest++;
	}
	while (*dest++ = *src++)
	{
		;
	}
	return ret;
}


int my_strcmp(const char* str1, const char* str2)
{
	assert(str1 != NULL);
	assert(str2 != NULL);
	while (*str1 == *str2)
	{
		if (*str1 == '\0')
			return 0;
		str1++;
		str2++;
	}
	return *str1 - *str2;
}

char* my_strstr(const char* str1, const char* str2)
{
	if (!*str2)
		return (char*)str1;
	char* cp = (char*)str1;
	char* s2;
	char* s1;
	while (*cp)
	{
		s1 = cp;
		s2 = (char*)str2;

		while (*s1 && *s2 && !(*s1 - *s2))
			s1++, s2++;
		if (!*s2)
			return cp;
		cp++;
	}
	return NULL;
}


int main1()
{
	char arr[100] = "1234567890";
	char brr[] = "456";
	printf("%s",my_strstr(arr,brr) );
	return 0;
}


int main2()
{
	char str1[] = "123.21.12@21.12";
		char str2[] = "@.";
		char str3[100];
		char *str4 = NULL;
		strcpy(str3, str1);
		for (str4 = strtok(str3, str2); str4 != NULL; str4 = strtok(NULL, str2))
		{
			printf("%s\n", str4);
		}
	return 0;
}



//int main3()
//{
//	printf("%d", islower('a'));
//	return 0;
//}



//#include <stdio.h>
#include <ctype.h>
//int main()
//{
//	int i = 0;
//	char str[] = "Test String.\n";
//	char c;
//	while (str[i])
//	{
//		c = str[i];
//		if (islower(c))
//			c = toupper(c);
//		i++;
//	}
//	printf("%s", str);
//	return 0;
//}


int main()
{
	char arr[20] = "1231231";
	char brr[] = "1237";
	printf("%d", strncat(arr, brr, 2));
	return 0;
}